<template>
	<base-page>
		<view class="uni-flex uni-row page-height">
			<view class="common-wrap left-wrap" style="flex: 1;">
				<view class="header-box">
					<view class="order-time">
						<view class="title">消费时间</view>
						<uni-datetime-picker v-model="orderData.create_time" type="datetime" :clearIcon="false" />
					</view>
					<view class="header" v-if="memberInfo"
						:style="'background-image:url(' + $util.img('public/uniapp/cashier/member-bg.png') + ');background-repeat: no-repeat;'">
						<view class="headimg" @click="showMember">
							<image class="header-image"
								:src="memberInfo.headimg ? $util.img(memberInfo.headimg) : $util.img(defaultImg.head)"
								@error="memberInfo.headimg = defaultImg.head"></image>
						</view>

						<view class="head-info" @click="showMember">
							<view class="head-info-top">
								<view class="name">
									<view class="text">{{ memberInfo.nickname }}</view>
									<view class="level" v-if="memberInfo.member_level">
										{{ memberInfo.member_level_name }}
									</view>
								</view>
								<view class="mobile">{{ memberInfo.mobile }}</view>
							</view>
							<view class="head-info-bottom">
								<view>积分：{{ memberInfo.point }}</view>
								<view>
									余额：{{ (parseFloat(memberInfo.balance_money) + parseFloat(memberInfo.balance)) | moneyFormat }}
								</view>
							</view>
						</view>

						<button class="switch primary-btn" @click="$refs.selectMember.open()">更换会员 [M]</button>
						<button class="switch primary-btn" @click="replaceMember()">散客</button>
					</view>
					<view class="header" v-else
						:style="'background-image:url(' + $util.img('public/uniapp/cashier/member-bg.png') + ');background-repeat: no-repeat;'">
						<view class="headimg">
							<image class="header-image" :src="$util.img(defaultImg.head)"></image>
						</view>
						<view class="head-info">
							<view class="name">散客</view>
						</view>
						<button class="switch primary-btn" @click="$refs.selectMember.open()">查询会员 [M]</button>
					</view>
				</view>

				<view class="content">
					<view class="title">
						<view>
							结算清单（
							<text>{{ orderData.goods_num }}</text>
							）
						</view>
						<view class="clear" @click="clearGoods">
							<text class="iconfont iconqingchushujuku"></text>
							<text>清空</text>
						</view>
					</view>

					<view class="contnet-list common-scrollbar">
						<block v-if="orderData.goods_list.length && Object.keys(goodsData).length">
							<view class="contnet-item" v-for="(item, index) in orderData.goods_list" :key="index">
								<view class="item-img">
									<image :src="$util.img(item.goods_image.split(',')[0], { size: 'small' })"
										mode="widthFix"></image>
								</view>
								<view class="item-info">
									<view class="item-name">{{ item.sku_name }}</view>
									<view class="item-del" @click="deleteGoods(item)">删除</view>
									<view class="item-spe" arrow-down>{{ item.spec_name }}</view>
									<view class="item-price">￥{{ item.price | moneyFormat }}</view>
								</view>
								<view class="item-num">
									<view class="num-dec" @click="dec(item)">-</view>
									<view class="num">{{ goodsData['sku_' + item.sku_id].num }}</view>
									<view class="num-inc" @click="inc(item)">+</view>
								</view>
							</view>
						</block>
						<block v-else>
							<view class="empty">
								<image :src="$util.img('public/uniapp/cashier/cart_empty.png')" mode="widthFix"></image>
								<view class="tips">点击右侧商品，选择商品进行结账</view>
							</view>
						</block>
					</view>
				</view>

				<view class="bottom">
					<view class="bottom-info">
						<view class="bottom-left">
							共
							<text>{{ orderData.goods_num }}</text>
							件
						</view>
					</view>
					<view class="bottom-btn">
						<text class="pay-money">￥{{ orderData.pay_money | moneyFormat }}</text>
						<!-- <button class="default-btn btn-left" :disabled="orderData.goods_num == 0"
							@click="pay('cash')">现金收款</button> -->
						<button class="primary-btn btn-right" :disabled="orderData.goods_num == 0" @click="pay('')">结账
							[Enter]</button>
					</view>
				</view>
				<view class="pay-shade" v-show="type == 'pay'"></view>
			</view>
			<view class="uni-flex uni-row common-wrap" style="flex: 2;">
				<view class="comp-wrap" v-show="type != 'pay'">
					<button class=" comp-btn" :class="type == 'goods' ? 'primary-btn' : 'default-btn'"
						@click="toGoods">卡项 [F2]</button>
					<button class=" comp-btn" :class="type == 'member' ? 'primary-btn' : 'default-btn'"
						@click="showMember">会员 [F3]</button>
				</view>

				<view class="list-wrap" style="flex: 1;">

					<!-- 卡项商品 -->
					<view class="content" v-show="type == 'goods'">
						<nc-card v-if="hackReset" @select="selectGoods" :type="orderData.card_type"
							ref="card"></nc-card>
					</view>

					<view class="content" v-show="type == 'member'">
						<nc-member-detail v-if="memberInfo" ref="memberDetail"
							:member-id="memberInfo.member_id"></nc-member-detail>
					</view>

					<view class="content" v-show="type == 'pay'">
						<nc-payment v-if="hackReset" ref="payment" :payMoney="orderData.pay_money"
							@cancel="cancelPayment" @success="paySuccess" :out-trade-no="outTradeNo"></nc-payment>
					</view>
				</view>
			</view>
		</view>

		<nc-select-member ref="selectMember"></nc-select-member>
	</base-page>
</template>

<script>
	import buycard from './public/js/buycard.js';
	import ncSelectMember from '@/components/nc-select-member/nc-select-member.vue';
	import ncMemberDetail from '@/components/nc-member-detail/nc-member-detail.vue';
	export default {
		components: {
			ncSelectMember,
			ncMemberDetail
		},
		mixins: [buycard]
	};
</script>

<style lang="scss" scoped>
	@import './public/css/index.scss';
</style>
<style>
	.header-box>>>.uni-select-lay-select {
		padding-right: 0.1rem !important;
	}

	.header-box>>>.uni-select-lay-icon {
		display: none !important;
	}

	.header-box>>>.uni-select-lay-input-close {
		display: none !important;
	}
</style>